package assignment01;

import java.io.Serializable;
import java.util.Comparator;

public class Trigram<F, S, T> implements Serializable {

	private static final long serialVersionUID = -7996805965957201063L;
	F first;
	S second;
	T third;
	
	public static class LexicographicTrigramComparator<F, S, T>  implements Comparator<Trigram<F, S, T>> {
	    Comparator<F> firstComparator;
	    Comparator<S> secondComparator;
	    Comparator<T> thirdComparator;

	    public int compare(Trigram<F, S, T> trigram1, Trigram<F, S, T> trigram2) {
	      int firstCompare = firstComparator.compare(trigram1.getFirst(), trigram2.getFirst());
	      if (firstCompare != 0)
	        return firstCompare;
	      int secondCompare = secondComparator.compare(trigram1.getSecond(), trigram2.getSecond());
	      if (secondCompare != 0)
	    	  return secondCompare;
	      return thirdComparator.compare(trigram1.getThird(), trigram2.getThird());
	    }

	    public LexicographicTrigramComparator(Comparator<F> firstComparator, Comparator<S> secondComparator, Comparator<T> thirdComparator) {
	      this.firstComparator = firstComparator;
	      this.secondComparator = secondComparator;
	      this.thirdComparator = thirdComparator;
	    }
	  }


	  public F getFirst() {
	    return first;
	  }

	  public S getSecond() {
	    return second;
	  }
	  
	  public T getThird() {
		  return third;
	  }

	  public void setFirst(F pFirst) {
	    first = pFirst;
	  }

	  public void setSecond(S pSecond) {
	    second = pSecond;
	  }

	  public void setThird(T pThird) {
		  third = pThird;
	  }

	  public boolean equals(Object o) {
	    if (this == o) return true;
	    if (!(o instanceof Trigram)) return false;

	    @SuppressWarnings("unchecked")
		final Trigram<F, S, T> trigram = (Trigram<F, S, T>) o;

	    if (first != null ? !first.equals(trigram.first) : trigram.first != null) return false;
	    if (second != null ? !second.equals(trigram.second) : trigram.second != null) return false;
	    if (third != null ? !third.equals(trigram.third) : trigram.third != null) return false;

	    return true;
	  }

	  public int hashCode() {
	    int result;
	    result = (first != null ? first.hashCode() : 0);
	    result = 29 * result + (second != null ? second.hashCode() : 0);
	    result = 29 * result + (third != null ? third.hashCode() : 0);
	    return result;
	  }

	  public String toString() {
	    return "(" + getFirst() + ", " + getSecond() + ", " + getThird() + ")";
	  }

	  public Trigram(F first, S second, T third) {
	    this.first = first;
	    this.second = second;
	    this.third = third;
	  }
	  
	  public Trigram() {
		  
	  }
}
